#include <iostream>
using namespace std;

#include <vector>
#include <algorithm>

extern void Print(vector<int> v);
extern void Vector_vector_print(vector<vector<int>>& ret);

vector<vector<int>> fourSum(vector<int>& nums, int target)
{
    sort(nums.begin(), nums.end());

    int n = nums.size();
    vector<vector<int>> ret;

    for (int i = 0; i < n - 3; ++i)
    {
        if ( i > 0 && nums[i - 1] == nums[i])
            continue;

        for (int j = i + 1; j < n - 2; ++j)
        {
            if (  (j > i + 1 && nums[j - 1] == nums[j]))
                continue;

            int left = j + 1, right = n - 1;
            while (left < right)
            {
                int sum = nums[i] + nums[j] + nums[left] + nums[right];
                if (sum > target)
                    --right;
                else if (sum < target)
                    ++left;
                else
                {
                    ret.push_back({ nums[i], nums[j], nums[left], nums[right] });

                    ++left;
                    while (left < right && nums[left] == nums[left - 1])
                        ++left;

                    --right;
                    while (left < right && nums[right] == nums[right + 1])
                        --right;
                }


            }
        }
    }

    return ret;
}


void test_fourNumSum1()
{
    vector<int> nums{ 1000000000,1000000000,1000000000,1000000000 };

    vector<vector<int>> ret = fourSum(nums, 0);

    Vector_vector_print(ret);
}


int main111111()
{
    test_fourNumSum1();
    //testVector();
    return 0;
}